<template>
  <el-container>
    <el-header class="homeHead">
      <i class="fa-home"></i>
      <div>云E办系统</div>
      <el-dropdown @command="handleCommand">
  <span class="el-dropdown-link">
   {{ admin.name }} <i style="margin-left: 10px"> <img style="width: 25px;height: 25px;border-radius: 50%" :src="admin.userFace">  </i>
  </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="userinfo">主页</el-dropdown-item>
          <el-dropdown-item command="setting">设置</el-dropdown-item>
          <el-dropdown-item command="logout">注销</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu :default-openeds="['1']" router unique-opened>
          <el-submenu :index="index+''" v-for="(item,index) in routes" :key="index" v-show="item.hidden!=true">
            <template slot="title"><i class="el-icon-message"></i>{{ item.name }}</template>
            <el-menu-item-group>
              <el-menu-item :index="children.path" v-for="(children,index) in item.children" :key="index">
                {{ children.name }}
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <el-breadcrumb separator="/" v-if="this.$router.currentRoute.path!='/home'">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
        </el-breadcrumb>
        <div v-if="this.$router.currentRoute.path==='/home'">
          欢迎来到云E办
        </div>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import axios from "axios";

export default {
  name: "Home",
  data() {
    return {

    }
  },
  computed: {
    routes() {
      return this.$store.state.routes;
    },
    admin(){
      return this.$store.state.currentAdmin
    }
  },
  methods: {
    handleCommand(command) {
      if (command === 'logout') {
        this.$confirm('此操作将注销, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          axios({method: 'post', url: '/api/logout'})
          window.sessionStorage.removeItem('tokenStr')
          window.sessionStorage.removeItem('user')
          this.$store.commit('initRoutes',[])
          this.$router.replace('/')
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }
      if(command == 'userinfo'){
        this.$router.replace('/userinfo')
      }
    }
  }
}
</script>

<style scoped>
.homeHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 30px;
  font-family: '仿宋 常规';
  background-color: #DCD9D4;
  background-image: linear-gradient(to bottom, rgba(255,255,255,0.50) 0%, rgba(0,0,0,0.50) 100%), radial-gradient(at 50% 0%, rgba(255,255,255,0.10) 0%, rgba(0,0,0,0.50) 50%);
  background-blend-mode: soft-light,screen;
}
.el-dropdown-link{
  display: flex;
  align-items: center;
  cursor: pointer;
}
</style>